<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增展示图片')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body>
    <div class="main-content">
        <form id="form-user-add" class="form-horizontal">
            <div class="row">
            	<div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">展示图片：</label>
                        <div class="col-sm-8">
                            <input id="fileinput-input" name="image" class="form-control" type="text" style="display: None">
                            <div class="fileinput fileinput-new" data-provides="fileinput">
                                <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px;"></div>
                                <div>
                                    <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span>
                                        <input name="fileinput-1" id ="fileinput-1" type="file">
                                    </span>
                                    <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">序号：</label>
                        <div class="col-sm-8">
                            <input id="orderId" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
	<th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script type="text/javascript">
        $(document).ready(function () {
            $("#fileinput-1").fileinput({
                'name':'text-1',
                'clearName':true
            });
            $("#fileinput-1").on("change.bs.fileinput", function (event, data, previewId, index) {
                var file =  this.files[0];
                if (file == null || file == undefined){
                    alert("置空");
                    return;
                }
                var formFile = new FormData();
                formFile.append("action", "UploadVMKImagePath");
                formFile.append("file", file); //加入文件对象
                var data = formFile;
                $.ajax({
                    url: "/common/upload",
                    type: "POST",
                    data:data,
                    dataType: "json",
                    cache:false,         //不设置缓存
                    processData: false,  // 不处理数据
                    contentType: false,   // 不设置内容类型
                    success: function (result) {
                        console.log(result);
                        if(result.code == 0){
                            $('#fileinput-input').val(result.url);
                            alert("上传完成!");
                        }else{
                            alert("上传失败");
                        }
                    },
                });
            });
        });

        /* 添加用户-选择用户-提交 */
        function submitHandler(index, layero) {
            var image = $('#fileinput-input').val();
            var orderId = $('#orderId').val();
            console.log(image);
            console.log(orderId);
//            if (image.length == 0) {
//                $.modal.alertWarning("请至少选择一条记录");
//                return;
//            }
            $.modal.close();
            // 父页面的方法
            // parent.selectUsers();
            // 父页面的变量
            var randomId = 100 + ~~(Math.random() * 100)
            parent.$.btTable.bootstrapTable('insertRow', {
                index: 0, // 你想插入到哪，0表示第一行
                row: {
                    orderId: orderId,
                    image: image,
                    imageId:randomId
                }
            })
        }
    </script>
</body>
</html>
